

import java.io.IOException;
import java.util.*;

public class UserInfo {

	private HashMap<Integer, String> userInfo = new HashMap(); //Stores user information IP, port and ID
	private List<Integer> generated = new ArrayList<Integer>();  
	private HashMap<Integer, String> userGroup; //stores group/groups selected by the user
	
	/**
	 * @param args
	 */
	
	public UserInfo(){
		userGroup = new HashMap();	
	}
	
	public HashMap getUserInfo(){
		return userInfo;
	}
	
	public HashMap getUserGroup(){
		return userGroup;
	}
	
	/**
	 * checks if the groups sent by user are in appropriate format or not and then adds it to the hashmap
	 * @param ID
	 * @param groups
	 */
	public void addUserToGroup(int ID, String groups){
		String delims = "[,]+";
		String[] tokens = groups.split(delims);
		for(int i=0; i<tokens.length; i++){
			try{
			Integer.parseInt(tokens[i]);
			userGroup.put(ID, groups);
		}catch(Exception e){
			System.out.println("group not in proper format");
		}
	}
		
	}
	
	/**
	 * parses string
	 * @param sentence
	 * @return
	 */
	public String stringParse(String sentence){
		String delims = "[=/:]+";
		String[] tokens = sentence.split(delims);
		//for(String item: tokens){
			String IP = tokens[1];
		int port = Integer.parseInt(tokens[2]);
		//System.out.println(IP + " "+port);
		String s = IP + " " + port;
		return s;
	}
	

}
